package com.yehuishou.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yehuishou.pojo.HUser;
import com.yehuishou.pojo.Permission;
import com.yehuishou.service.AdminService;
import com.yehuishou.service.HUserService;
import com.yehuishou.service.PermissionService;

/**
 * 权限
 * @author zxb
 *
 */
@Controller
public class PermissionController {
	
	@Autowired
	private PermissionService permissionService;
	@Autowired
	private HUserService huserService;
	@Autowired
	private AdminService adminService;

	@RequestMapping("permission")
	public String permissionFind(Integer h_uid ,HttpServletRequest req, Model model) {
		HUser huer = new HUser();
		huer.setH_uid(h_uid);
		HUser huser = huserService.findById(h_uid);
		List<Permission> list = permissionService.findByHUser(huer);
		List<Integer> list1 = new ArrayList<Integer>();
		for (Permission per : list) {
			list1.add(per.getId());
		}
		req.getSession().setAttribute("list", list1);
		model.addAttribute("HUser", huser);
		return"content-6_3_edit";
	}
	
	@RequestMapping("perupdate")
	public String permissionUpdate(HUser huser , Integer[] perid) {
		//修改用户信息
		adminService.HUserUpdate(huser);
		//修改权限
		permissionService.perUpdate(perid , huser.getH_uid());
		return "redirect:/adminlist";
	}
}
